package com.itheima.controller;

import com.itheima.pojo.OmsOrderReturnReason;
import com.itheima.service.OmsOrderReturnReasonService;
import com.itheima.vo.PageResultVo;
import com.itheima.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/returnReason")
public class OmsOrderReturnReasonController {
    @Autowired
    private OmsOrderReturnReasonService service;

    //添加
    @PostMapping("/create")
    public ResponseEntity create(@RequestBody OmsOrderReturnReason reason) {
        service.create(reason);
        return ResponseEntity.ok(Result.success(null));
    }

    //批量删除
    @PostMapping("/delete")
    public ResponseEntity delete(@RequestParam List<Long> ids) {
        service.delete(ids);
        return ResponseEntity.ok(Result.success(null));
    }

    //分页查询
    @GetMapping("/list")
    public ResponseEntity list(@RequestParam Integer pageNum,
                               @RequestParam Integer pageSize) {
        PageResultVo vo = service.list(pageNum, pageSize);
        return ResponseEntity.ok(Result.success(vo));
    }

    //修改启用状态
    @PostMapping("/update/status")
    public ResponseEntity updateStatus(@RequestParam Integer ids,
                                       @RequestParam Integer status) {
        service.updateStatus(ids, status);
        return ResponseEntity.ok(Result.success(null));
    }

    //修改退货原因
    @PostMapping("/update/{id}")
    public ResponseEntity updateById(@RequestBody OmsOrderReturnReason reason,
                                     @PathVariable("id") Long id) {
        reason.setId(id);
        service.updateByid(reason);
        return ResponseEntity.ok(Result.success(null));
    }
    @GetMapping("/{id}")
    public ResponseEntity findById(@PathVariable("id")Long id){
        OmsOrderReturnReason reason=  service.findById(id);
        return ResponseEntity.ok(Result.success(reason));
    }
}
